#include <iostream>
using namespace std;

class GameofLife {

   private:			//User cannot change these variables directly
      char** Grid;
      int Row;
	  int Col;
      static const char litCellMark    = 'X';
      static const char unlitCellMark  = ' ';
      
   protected:
       char** buildGrid(int, int) const;
       char** copyGrid(char**, int, int) const; 
       void setGridElt(int, int, char);
       void deallocateGrid( );
       
public:
	GameofLife(int R,int C):Row(R),Col(C){
        if((Row <= 1)||(Col <= 1)) throw "invalid values passed to GameofLife::GameofLife";
        Grid = buildGrid(Row, Col);
	    for(int i=0;i<Row;i++) 
			for(int j=0; j<Row; j++)
               unlightCell(i, j);        
    }
   ~GameofLife( ){deallocateGrid( );};
   
   
    void draw() const{
        for (int i=0;i<Row;i++)
		    printf("%s\n", Grid[i]);	
		}
		
    void lightCell(int i,int j){
         setGridElt(i,j,litCellMark);
         }
    void unlightCell(int i,int j){
         setGridElt(i,j,unlitCellMark);
         }
        bool isLit(int i, int j) const{
         return Grid[i][j] == litCellMark;
         }
         
   void evolve( );
   int countLitNeighbors(int, int) const;
   bool isLitInNextEvolution(int i, int j) const;
  

};
